﻿using System;
using System.Linq;
using Loki.Engine;
using Loki.Model;
using Luna.Data;

namespace Luna.Model.Security
{
    internal class CacheConfiguration : CacheConfiguration<LunaDataModel>
    {
        public static readonly ContainerConfiguration<IUser, Guid> USERS = new ContainerConfiguration<IUser, Guid>()
        {
            LoadingErrorCode = ErrorCodes.SEC_010,
            FullLoader = () => DataContext.Security.GetAllUsers().Select(x => new User(x)),
            Indexes = new IIndexConfiguration<IUser>[]
            {
                new IndexConfiguration<IUser, string>() { Indexer = u => u.Login }
            },
            PrimaryKey = new UniqueKeyConfiguration<IUser, Guid>()
            {
                Indexer = u => ((ILunaEntity)u).ID,
                Loader = g => new User(DataContext.Security.GetUser(g))
            }
        };
    }
}
